package com.nexgo.payment.trans.refund;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.nexgo.payment.R;
import com.nexgo.payment.action.inputadminpwd.AdminPasswordFragment;
import com.nexgo.payment.action.inputdate.InputDateFragment;
import com.nexgo.payment.action.inputrefno.InputRefNoFragment;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.AbsTransActivity;
import com.nexgo.payment.util.ActivityUtils;

/**
 * 银行卡退货
 *
 * @author 谭忠扬-YuriTam
 * @time 2017年8月24日
 */
public class RefundActivity extends AbsTransActivity<RefundContract.Presenter> implements RefundContract.View {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getIntent().getExtras();
        boolean isOnlineRefund = false;
        if (args != null) {
            isOnlineRefund = args.getBoolean("online", false);
        }
        new RefundPresenter(this, Repository.getInstance(),isOnlineRefund);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.start();
    }

    @Override
    public void showInputAdminPassword() {
        AdminPasswordFragment adminPwdFragment = AdminPasswordFragment.newInstance();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), adminPwdFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), adminPwdFragment, R.id.contentFrame);
        }
    }
    public static Intent newInstance(Context context, boolean online) {
        Intent intent = new Intent(context, RefundActivity.class);
        Bundle bundle = new Bundle();
        bundle.putBoolean("online",online);
        intent.putExtras(bundle);
        return intent;
    }
    @Override
    public void showInputRefNo() {
        InputRefNoFragment refNoFragment = InputRefNoFragment.newInstance();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), refNoFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), refNoFragment, R.id.contentFrame);
        }
    }

    @Override
    public void showInputDate() {
        InputDateFragment inputDateFragment = InputDateFragment.newInstance();
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), inputDateFragment, R.id.contentFrame);
        } else {
            ActivityUtils.replaceFragmentToActivity(getSupportFragmentManager(), inputDateFragment, R.id.contentFrame);
        }
    }
}
